home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-03 | 14.1 KB | 424 lines | [TEXT/MPS ] |
- // UTEDocument.h
- // Copyright © 1984-95 by Apple Computer, Inc. All rights reserved.
-
- #ifndef __UTEDOCUMENT__
- #define __UTEDOCUMENT__
-
- //----------------------------------------------------------------------------------------
- // This separate unit for TE Documents is still an example and not a supported Building
- // Block. It provides a backing document for those times when you want to write your
- // TEView to external media. Remember, since its not a building block right now the
- // structure is subject to more than the usual amount of change. Let us know what you
- // think.
- //----------------------------------------------------------------------------------------
-
- //----------------------------------------------------------------------------------------
- // This document can be built without printing support by changing the following flag
- //----------------------------------------------------------------------------------------
- #if !defined(UsingDemoTextPrinting)
- #define UsingDemoTextPrinting 1
- #endif
-
-
- #if qPowerTalk
- #ifndef __UMAILABLEDOCUMENT__
- #include "UMailableDocument.h"
- #endif
- #else
- #ifndef __UFILEBASEDDOCUMENT__
- #include "UFileBasedDocument.h"
- #endif
- #endif
-
- #ifndef __UTEVIEW__
- #include "UTEView.h"
- #endif
-
-
- const unsigned long kTextFileType = 'TEXT'; // Standard file-type code for saved disk
- // files -- uses standard text files
-
- const unsigned long kScrapType = 'TEXT'; // Standard scrap-type code for
- // WriteToScrap
-
- const ResNumber kWindowRsrcID = 1004; // 'view' template for a DemoText window
-
- const ResNumber kViewRsrcID = 1005; // 'view' template for a DemoText view
-
-
- //----------------------------------------------------------------------------------------
- // Menu numbers
- //----------------------------------------------------------------------------------------
-
- const short mFont = 10;
-
-
- //----------------------------------------------------------------------------------------
- // Command numbers
- //----------------------------------------------------------------------------------------
-
- const CommandNumber cWidthSuperView = 701; // View-width-determination commands
- const CommandNumber cWidthView = 702;
- const CommandNumber cWidthOnePage = 703;
-
- const CommandNumber cHeightSuperView = 704; // View-height-determination commands
- const CommandNumber cHeightPages = 705;
- const CommandNumber cHeightText = 706;
- const CommandNumber cHeightConst = 707;
-
- const CommandNumber cJustForceLeft = 708; // Justification commands
- const CommandNumber cJustCenter = 709;
- const CommandNumber cJustRight = 710;
- const CommandNumber cJustSystem = 711;
-
- // Command numbering scheme:
- // styles = 720-729
- // sizes = 800-899
- // just = 730-739
- // fonts = 740-749
- // hiers = 750-759
- // colors = 760-769
-
-
- //----------------------------------------------------------------------------------------
- // Command numbers for typestyle attributes
- //----------------------------------------------------------------------------------------
-
- const CommandNumber cPlainText = 720;
- const CommandNumber cBold = 721;
- const CommandNumber cItalic = 722;
- const CommandNumber cUnderline = 723;
- const CommandNumber cOutline = 724;
- const CommandNumber cShadow = 725;
- const CommandNumber cCondense = 726;
- const CommandNumber cExtend = 727;
-
-
- //----------------------------------------------------------------------------------------
- // Command numbers for font-size commands
- //----------------------------------------------------------------------------------------
-
- const CommandNumber cSizeChange = 800;
- const CommandNumber cSizeBase = 800;
- const CommandNumber cSizeMin = 809;
- const CommandNumber cSizeMax = 896;
- const CommandNumber cSizeOther = 897;
-
- //----------------------------------------------------------------------------------------
- // 801-897 reserved for font sizes 1-97 pts.
- //----------------------------------------------------------------------------------------
-
- const CommandNumber cSizeGrow = 898;
- const CommandNumber cSizeShrink = 899;
-
-
- //----------------------------------------------------------------------------------------
- // Command numbers to cover other stylistic changes
- //----------------------------------------------------------------------------------------
-
- const CommandNumber cJustChange = 730;
- const CommandNumber cFontChange = 731;
-
-
- //----------------------------------------------------------------------------------------
- // Command numbers for the hierarchial menu
- //----------------------------------------------------------------------------------------
-
- const CommandNumber cStyle = 750;
- const CommandNumber cSize = 751;
- const CommandNumber cFont = 752;
- const CommandNumber cColor = 753;
-
-
- //----------------------------------------------------------------------------------------
- // Command numbers for changing colors
- //----------------------------------------------------------------------------------------
-
- const CommandNumber cColorChange = 760;
- const CommandNumber cColorText = 761;
- const CommandNumber cColorBackground = 762;
-
-
- //----------------------------------------------------------------------------------------
- // Constant for staggering windows
- //----------------------------------------------------------------------------------------
-
- const short kStaggerAmount = 16;
-
-
- //----------------------------------------------------------------------------------------
- // Constant for amount to relative size text selection
- //----------------------------------------------------------------------------------------
-
- const short kRelSizeAmount = 4;
-
-
- //----------------------------------------------------------------------------------------
- // Constants for the text specs resource
- //----------------------------------------------------------------------------------------
-
- const ResType kTextSpecsRsrcType = 'SPEC';
- const ResNumber kTextSpecsRsrcID = 1;
-
-
- //----------------------------------------------------------------------------------------
- // Constants for the text style resource
- //----------------------------------------------------------------------------------------
-
- const ResType kTextStyleRsrcType = 'STYL';
- const ResNumber kStylesRsrcID = 1;
- const ResNumber kElementsRsrcID = 2;
-
-
- //----------------------------------------------------------------------------------------
- // Constants for the prompts CString list
- //----------------------------------------------------------------------------------------
- const ResNumber kPromptsRsrcID = 1005;
- const short kColTextPrompt = 1;
- const short kColBackPrompt = 2;
-
- #if qPowerTalk
- const short kReplySpacer = 3;
- const ResNumber kContentNotExtracted = 1017;
- const ResNumber kSnapshotNotExtracted = 1018;
- #endif
-
- const ResNumber kFileTooBig = 1000; // The 'File is too large' alert
-
-
- const ResNumber kHierDisplayedMBar = 131; // Displayed menus on hier. menu system
- const ResNumber kNonHierDisplayedMBar = 128; // Displayed menus on non-hier. system
-
- const short kHierMenuOffset = 1000; // Offset added to non-hier menu cmds to
- // get the right number
-
-
- //============================================================================================
- // Data read from or written to disk files or exchanged via clip must be built to use the same
- // alignment. We choose to center on mac68K alignment. In your application you may choose any
- // data alignment that you wish, so long as both your PPC and 68K code agree on it.
- //============================================================================================
- #if PRAGMA_ALIGN_SUPPORTED
- #pragma options align=mac68k
- #endif
-
- //----------------------------------------------------------------------------------------
- // TextSpecs: Additional document specifications
- //----------------------------------------------------------------------------------------
- struct TextSpecs
- {
- public:
- // constructors
- inline TextSpecs() {}
-
- inline TextSpecs(const TextSpecs& copyTextSpecs) :
- theTextFont(copyTextSpecs.theTextFont),
- theTextFace(copyTextSpecs.theTextFace),
- theTextSize(copyTextSpecs.theTextSize),
- theTextColor(copyTextSpecs.theTextColor),
- theJustification(copyTextSpecs.theJustification),
- theBackColor(copyTextSpecs.theBackColor) {}
-
- // Assignment operator
-
- inline TextSpecs& operator =(const TextSpecs& aTextSpecs);
-
- //----------------------------------------------------------------------------------------
- // data members
- //----------------------------------------------------------------------------------------
- public:
- CStr255 theTextFont;
- Style theTextFace;
- short theTextSize;
- CRGBColor theTextColor;
- short theJustification; // record justification
- CRGBColor theBackColor; // Window's background color
- };
-
- typedef TextSpecs *TextSpecsPtr, **TextSpecsHdl;
-
- #if PRAGMA_ALIGN_SUPPORTED
- #pragma options align=reset
- #endif
- //============================================================================================
- //============================================================================================
-
-
- inline TextSpecs& TextSpecs::operator = (const TextSpecs& aTextSpecs)
- {
- MABlockMove(&aTextSpecs.theTextFont, &theTextFont, sizeof(TextSpecs));
-
- return *this;
- }
-
- //----------------------------------------------------------------------------------------
- // External and forward class declarations.
- //----------------------------------------------------------------------------------------
-
- class TTEView;
- class TFile;
-
-
- //----------------------------------------------------------------------------------------
- // TTEDocument
- //----------------------------------------------------------------------------------------
-
- #if qPowerTalk
- class TTEDocument : public TMailableDocument
- #else
- class TTEDocument : public TFileBasedDocument
- #endif
- {
-
- MA_DECLARE_CLASS;
-
- public:
- //------------------------------------------------------------------------------------
- // Initialization and freeing
- //------------------------------------------------------------------------------------
-
- TTEDocument();
-
- virtual void ITEDocument(TFile* itsFile,
- const OSType itsScrapType,
- ResNumber itsViewResourceID);
- // Initialization method for TTEDocument.
-
- virtual ~TTEDocument();
-
- virtual void DoInitialState();
-
- virtual void FreeData();
-
-
- //------------------------------------------------------------------------------------
- // Filing
- //------------------------------------------------------------------------------------
-
- virtual void DoNeedDiskSpace(TFile* itsFile,
- long& dataForkBytes,
- long& rsrcForkBytes);
-
- virtual void DoRead(TFile* aFile, Boolean forPrinting);
-
- virtual void DoWrite(TFile* aFile, Boolean makingCopy);
-
- #if qPowerTalk
- //------------------------------------------------------------------------------------
- // PowerTalk Support
- //------------------------------------------------------------------------------------
-
- virtual void AddStandardMailContent(Boolean& okToSend);
-
- virtual Boolean ReadStandardMailContent();
-
- virtual Boolean ReadNativeMailContent();
-
- virtual Boolean ReadSnapshotMailContent();
-
- virtual void SetReplyContents(TDocument* replyToDoc);
-
- virtual void ImageDocumentForLetter(Boolean inColor);
- #endif // qPowerTalk
-
- //------------------------------------------------------------------------------------
- // Making views and windows
- //------------------------------------------------------------------------------------
-
- virtual void DoMakeViews(Boolean forPrinting);
-
-
- //------------------------------------------------------------------------------------
- // Command processing
- //------------------------------------------------------------------------------------
-
- virtual void DoMenuCommand(CommandNumber aCommandNumber);
-
- virtual void DoSetupMenus();
-
-
- //------------------------------------------------------------------------------------
- // Auxiliary routines
- //------------------------------------------------------------------------------------
-
- virtual void ChangeBackColor(const CRGBColor& newColor);
-
- virtual void SetSpecStyle();
-
- virtual void ShowReverted();
- // When the user reverts a document, this is called after reading the old document
- // and before displaying it. Causes the reverted font specs to be installed.
-
- protected:
- void DoJustChange(CommandNumber aCommandNumber);
-
- void DoStyleChange(CommandNumber aCommandNumber);
-
- void DoColTextChange();
-
- void DoColBackChange();
-
- void InstallChangedDeterminer(VHSelect vhs, SizeDeterminer sd);
-
- void DoWidthChange(CommandNumber aCommandNumber);
-
- void DoHeightChange(CommandNumber aCommandNumber);
-
- //----------------------------------------------------------------------------------------
- // data members
- //----------------------------------------------------------------------------------------
- public:
- TextSpecs fTextSpecs; // Specifies properties of the text
- TTEView* fTEView; // The view which displays the text
- Handle fDocText; // The text owned by the document
- TEStyleHandle fStyles; // Style handle, if any
- STHandle fElements; // Handle to element array, if any
- ResNumber fViewResourceID; // ID of 'view' resource
-
- //----------------------------------------------------------------------------------------
- // static data members
- //----------------------------------------------------------------------------------------
- public:
- static TextSpecs gDefaultSpecs;
- // Text specs as default for new documents
-
- };
-
-
- class TJustCommand : public TCommand
- {
-
- MA_DECLARE_CLASS;
-
- public:
- TJustCommand();
- // Puts a newly created TJustCommand into a known state. Subclasses should
- // override it and call INHERITED. Typically used to put the object into a state
- // where it can be safely FREED.
-
- virtual ~TJustCommand();
- // Destructor
-
- virtual void IJustCommand(TTEView* itsTEView, short itsNewJust);
-
- virtual void DoIt();
-
- virtual void UndoIt();
-
- //----------------------------------------------------------------------------------------
- // data members
- //----------------------------------------------------------------------------------------
- public:
- TTEView* fTEView;
- short fOldJust;
- short fNewJust;
- };
-
- // ---------------------------------------------------------------------------------------
- void InitUTEDocument();
- // Initialize TEDocument unit.
-
- #endif
-
-
-